<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="维修工种" prop="major">
        <el-input
            v-model="queryParams.major"
            placeholder="请输入维修工种"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="维修师名称" prop="workName">
        <el-input
            v-model="queryParams.workName"
            placeholder="请输入维修师名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            size="small"
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="noticeList" highlight-current-row @current-change="handleCurrentChange">
      <el-table-column label="序号" align="center" prop="index" width="60" type="index"/>
      <el-table-column
          label="维修师名称"
          align="center"
          prop="workName"
          :show-overflow-tooltip="true"
      />
      <el-table-column label="工种" align="center" prop="major"/>
      <el-table-column label="维修技能" align="center" prop="memo"/>
      <el-table-column label="电话" align="center" prop="phone"/>
      <!--<el-table-column fixed="right" label="操作" align="center" width="150" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleToMake(scope.row)" size="small">编辑</el-button>
          <el-button link @click="handleDetail(scope.row)" size="small">删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" v-model="open" width="60%" append-to-body>
      <el-form ref="uform" :model="params" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="维修人名称" prop="workName">
              <el-input v-model="params.workName" placeholder="请输入维修人名称" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="维修工类型" prop="workType">
              <el-select v-model="params.workType" placeholder="请选择">
                <el-option label="公司员工" :value="1"></el-option>
                <el-option label="厂家员工" :value="2"></el-option>
                <el-option label="社会散工" :value="3"></el-option>
                <el-option label="甲方人员" :value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="城市" prop="city">
              <el-input v-model="params.city" placeholder="请输入城市" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="公司" prop="company">
              <el-input v-model="params.company" placeholder="请输入公司" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="专业" prop="major">
              <el-input v-model="params.major" placeholder="请输入专业" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="擅长内容" prop="memo">
              <el-input v-model="params.memo" placeholder="请输入擅长内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="手机" prop="phone">
              <el-input v-model="params.phone" placeholder="请输入手机" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="结算方式" prop="payType">
              <el-select v-model="params.payType" placeholder="请选择">
                <el-option label="按月结算" :value="1"></el-option>
                <el-option label="按次结算" :value="2"></el-option>
                <el-option label="临时报价" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="金额" prop="price">
              <el-input v-model="params.price" placeholder="请输入金额" />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="params.sex" placeholder="请选择">
                <el-option label="男" :value="1"></el-option>
                <el-option label="女" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Notice">
import {listNotice, workerInsert} from "@/api/system/repairman.js"

const {proxy} = getCurrentInstance()

const noticeList = ref([])
const title = ref('新增')
const loading = ref(true)
const open = ref(false)
const total = ref(0)
const rules = ref([])
let params = reactive({
  city: "",//城市
  company: "",//公司
  major: "",//专业
  memo: "",//擅长内容
  payType: 1,//结算方式 1 按月结算 2 按次结算 3临时报价
  phone: "",//手机
  price: null,//金额
  qualificationsPics: "",
  sex: 1,//1 男 2 女
  workName: "",//维修人员名称
  workType: 1,//维修工类型 1 公司员工 2 厂家员工 3 社会散工 4甲方人员
})
const data = reactive({
  queryParams: {
    page: 1,
    pageSize: 10,
    major: undefined,
    workName: undefined
  }
})
const currentRow = ref()

const {queryParams} = toRefs(data)

/** 查询公告列表 */
function getList() {
  loading.value = true
  listNotice(queryParams.value).then(response => {
    noticeList.value = response.data.list
    total.value = response.data.total
    loading.value = false
  }).catch((err) => {
    console.log(err)
    loading.value = false
  })
}

//表格单选
const handleCurrentChange = (val) => {
  currentRow.value = val
}

function cancel() {
  open.value = false
}

/** 提交按钮 */
function submitForm() {
  workerInsert(params).then(res => {
    if (res.code === 200) {
      proxy.$modal.msgSuccess(res.msg)
      open.value = false
      getList()
    }
  })
}

const handleAdd = () => {
  open.value = true
}
const handleToMake = (val) => {
  open.value = true
  params = val
}
const handleDetail = (val) => {
  open.value = true
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

//暴露给父组件的属性
defineExpose({currentRow})

getList()
</script>
